<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="jquery-1.8.3.min.js"></script>
    <script type="text/javascript">
    
    	var filecontent;
    	
        /*
        * @description: read local text file via the html5 FileReader
        **/
        function getFileContent(fileInput, callback) {
            if (fileInput.files && fileInput.files.length > 0 && fileInput.files[0].size > 0) {
                var file = fileInput.files[0];
                if (window.FileReader) {
                    var reader = new FileReader();

                    reader.onloadend = function (evt) {
                        if (evt.target.readyState == FileReader.DONE) {
                            callback(evt.target.result.split(',')[1]);
                        }
                    }

                    reader.readAsDataURL(file);
                }
            }
        }

        function decode_base64(s) { var e = {}, i, k, v = [], r = '', w = String.fromCharCode; var n = [[65, 91], [97, 123], [48, 58], [43, 44], [47, 48]]; for (z in n) { for (i = n[z][0]; i < n[z][1]; i++) { v.push(w(i)); } } for (i = 0; i < 64; i++) { e[v[i]] = i; } for (i = 0; i < s.length; i += 72) { var b = 0, c, x, l = 0, o = s.substring(i, i + 72); for (x = 0; x < o.length; x++) { c = e[o.charAt(x)]; b = (b << 6) + c; l += 6; while (l >= 8) { r += w((b >>> (l -= 8)) % 256); } } } return r; }

        $(function () {
            $('#b1').click(function () {
		// please do not use $('f1') to get the file dom element, otherwise, you'll get a js error.
                getFileContent(document.getElementById('f1'), function (str) {
                    
                    alert(decode_base64(str));
                    filecontent = str;
					//document.getElementById("contents").innerHTML=decode_base64(str);
                });
            });
			document.getElementById("contents").innerHTML=decode_base64(str);
        });
        
		
    </script>
</head>
<body>
    <input type="file" id="f1" />
    <input type="button" id="b1" value="read" />
    <p> Number of Incidents: <span id="contents"></span> </p>
</body>
</html>